package com.longge;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-03-09 23:22
 */
public class NumIdenticalPairs {

    public int numIdenticalPairs(int[] nums) {
        int res = 0;
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int num : nums) {
            Integer count = map.getOrDefault(num, 0);
            map.put(num, ++count);
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            Integer value = entry.getValue();
            if (value > 1) {
                res += mul(value)/2;
            }
        }
        return res;
    }

    int mul(int value){
        int res = 1;
        while (value!=0){
            res*=value--;
        }
        return res;
    }

    public static void main(String[] args) {
        new NumIdenticalPairs().numIdenticalPairs(new int[]{1,2,3,1,1,3});
    }
}
